package entity.table;

import com.google.common.base.CaseFormat;
import constant.table.ClazzConstact;
import entity.config.ApplicationGeneration;
import entity.config.TempleGeneration;
import enums.common.RuleEnum;
import enums.table.ClazzTypeEnum;

import java.io.Serializable;

public class TableInfoDto implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 表名
     */
    private String tableName;

    /**
     *  打包 实体类
     */
    private String entityPackaging;

    /**
     *  打包 service接口
     */
    private String servicePackaging;

    /**
     *  打包 service实现类
     */
    private String serviceImplPackaging;

    /**
     *  打包 dao
     */
    private String daoPackaging;

    /**
     *  打包 mapper.xml
     */
    private String mapperXmlPackaging;

    /**
     * 需要移除的前缀
     */
    private String removePrefix;

    /**
     * 服务器数据
     */
    private ApplicationGeneration application;

    /**
     * 模板数据
     */
    private TempleGeneration temple;

    public String getEntityPackaging() {
        return entityPackaging;
    }

    public void setEntityPackaging(String entityPackaging) {
        this.entityPackaging = entityPackaging;
    }

    public String getServicePackaging() {
        return servicePackaging;
    }

    public void setServicePackaging(String servicePackaging) {
        this.servicePackaging = servicePackaging;
    }

    public String getServiceImplPackaging() {
        return serviceImplPackaging;
    }

    public void setServiceImplPackaging(String serviceImplPackaging) {
        this.serviceImplPackaging = serviceImplPackaging;
    }

    public String getDaoPackaging() {
        return daoPackaging;
    }

    public void setDaoPackaging(String daoPackaging) {
        this.daoPackaging = daoPackaging;
    }

    public String getMapperXmlPackaging() {
        return mapperXmlPackaging;
    }

    public void setMapperXmlPackaging(String mapperXmlPackaging) {
        this.mapperXmlPackaging = mapperXmlPackaging;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getRemovePrefix() {
        return removePrefix;
    }

    public void setRemovePrefix(String removePrefix) {
        this.removePrefix = removePrefix;
    }

    public ApplicationGeneration getApplication() {
        return application;
    }

    public void setApplication(ApplicationGeneration application) {
        this.application = application;
    }

    public TempleGeneration getTemple() {
        return temple;
    }

    public void setTemple(TempleGeneration temple) {
        this.temple = temple;
    }
// =================================================================================================================

    public String getTableNameOriginal() {
        return tableName;
    }

    public String getTableName() {
        String tn = tableName;
        if (null != removePrefix) {
            tn = tn.replace(removePrefix, "");
        }
        return tn;
    }
    /**
     * 类名
     */
    public String getTableNameCamel() {
        String tn = tableName;
        if (null != removePrefix) {
            tn = tn.replace(removePrefix, "");
        }
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, tn);
    }

    /**
     * mapper 类名
     */
    public String getMapperName() {
        String tn = tableName;
        if (null != removePrefix) {
            tn = tn.replace(removePrefix, "");
        }
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, tn);
    }

    /**
     * 使用指定类型 生成 类名
     * getTableNameCamel(ClazzTypeEnum.VO) = XxxxxVo
     */
    public String getTableNameCamel(ClazzTypeEnum clazzTypeEnum) {
        if (clazzTypeEnum == null) {
            return this.getTableNameCamel();
        }
        if (ClazzTypeEnum.MAPPER.getSuffix().equals(clazzTypeEnum.getSuffix())) {
            return this.getMapperName() + "-" + clazzTypeEnum.getSuffix();
        }
        return this.getTableNameCamel() + clazzTypeEnum.getSuffix();
    }

    public String getTableName(ClazzTypeEnum clazzTypeEnum) {
        if (clazzTypeEnum == null) {
            return this.getTableName();
        }
        if (ClazzTypeEnum.MAPPER.getSuffix().equals(clazzTypeEnum.getSuffix())) {
            return this.getMapperName() + "-" + clazzTypeEnum.getSuffix();
        }
        return this.getTableName() + clazzTypeEnum.getSuffix();
    }

    /**
     * 使用指定类型 类路径
     * getPackaging(ClazzTypeEnum.VO) = XxxxxVo.java
     */
    public String getPackaging(ClazzTypeEnum clazzTypeEnum) {
        if (clazzTypeEnum == null) {
            return this.getEntityPackaging() + "." + getTableNameCamel();
        }

        // TODO 生成其他类的包名：
        // TODO 1. mapper.xml
        // TODO 2. 类的导入

        /*if (clazzTypeEnum) {

        }
        return new StringBuilder(this.getTableNameCamel())
                .append(clazzTypeEnum.getSuffix())
                .append(".")
                .append(ClazzConstact.JAVA).toString();*/
        return null;
    }

    /**
     * 使用指定类型 生成 文件名
     * getFileNameCamel(ClazzTypeEnum.VO) = XxxxxVo.java
     */
    public String getFileNameCamel(ClazzTypeEnum clazzTypeEnum) {
        if (clazzTypeEnum == null) {
            return this.getTableNameCamel();
        }

        if (ClazzTypeEnum.MAPPER.getSuffix().equals(clazzTypeEnum.getSuffix())) {
            return new StringBuilder(this.getMapperName())
                    .append("-")
                    .append(clazzTypeEnum.getSuffix())
                    .append(".")
                    .append(ClazzConstact.XML).toString();
        }

        return new StringBuilder(this.getTableNameCamel())
                .append(clazzTypeEnum.getSuffix())
                .append(".")
                .append(ClazzConstact.JAVA).toString();
    }

    /*// Vo 类名
    public String getTableNameVoCamel() {
        return this.getTableNameCamel() + "Vo";
    }

    // Query 类名
    public String getTableNameQueryCamel() {
        return this.getTableNameCamel() + "Query";
    }

    // Dto 类名
    public String getTableNameDtoCamel() {
        return this.getTableNameCamel() + "Dto";
    }

    // Service 类名
    public String getTableNameServiceCamel() {
        return this.getTableNameCamel() + "Service";
    }

    // ServiceImpl 类名
    public String getTableNameServiceImplCamel() {
        return this.getTableNameCamel() + "ServiceImpl";
    }

    // Dao 类名
    public String getTableNameDaoCamel() {
        return this.getTableNameCamel() + "Dao";
    }*/
}
